﻿using System.Collections.Generic;
using System.Configuration;
using Luminji.Core.Data;
using Luminji.Core.Json;
using Luminji.ExamWeb.Core.Domain.Model;
using Luminji.ExamWeb.Infrastructure.DataAccess.Impl;
using Luminji.ExamWeb.Infrastructure.DataAccess.Impl.SqlServer;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Luminji.Core.Serialization;
using Luminji.ExamWeb.Helpers.Tools;
using Luminji.Core.Xaml;
using Luminji.Core.Xaml.Common;

namespace IntegrationTests.DataAccess.Impl.SqlServer
{
    
    
    /// <summary>
    ///This is a test class for PaperRepositoryTest and is intended
    ///to contain all PaperRepositoryTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PaperRepositoryTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        [TestMethod]
        public void TestGetPapersBySubjectCode()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository pr = new PaperRepository();
            IList<Paper> re = pr.GetPapersBySubjectCode("21FB2FDCD4AA41C8A14776F3EA0F86C4");
        }

        [TestMethod]
        public void TestGetPapersBySubjectAndChildrenCode()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository pr = new PaperRepository();
            IList<Paper> re = pr.GetPapersBySubjectAndChildrenCode("811129BA861F4449BC442127167A5023");
        }

        [TestMethod]
        public void TestGetPapersBySubjectAndChildrenCodeInPage()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository pr = new PaperRepository();
            IList<Paper> re0 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 0);
            IList<Paper> re1 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 1);
            IList<Paper> re2 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 2);
            IList<Paper> re3 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 3);
            IList<Paper> re4 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 4);
            IList<Paper> re5 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 5);
            IList<Paper> re6 = pr.GetPapersBySubjectAndChildrenCodeInPage("811129BA861F4449BC442127167A5023", 6);
            
        }

        [TestMethod]
        public void TestGetPapersNumsBySubjectAndChildrenCode()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository pr = new PaperRepository();
            int re = pr.GetPapersNumsBySubjectAndChildrenCode("87BBA2FC5D884BB5910B6C67DA428C05");
        }

        [TestMethod]
        public void TestGetPaperWithDetailDetailByPaperCode()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository pr = new PaperRepository();
            Paper re = pr.GetPaperWithDetailDetailByPaperCode("4CF4798650D34D3BA0F377FDB8ECCD87");
            PaperFormator.PaperDetailsFormat(re.PaperDetails, "XAML");

            //string temp1 = @"<QuestionFlowDocument FontFamily="微软雅黑" FontSize="12" LineHeight="1" PagePadding="5,0,5,0" AllowDrop="True"  xmlns="clr-namespace:QuestionBank.Controls;assembly=QuestionBank.Controls"  xmlns:av="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><av:Paragraph Margin="0,0,0,0" FontFamily="宋体" FontSize="12"><av:Span xml:lang="en-us">Lincoln often visited hospitals ______.</av:Span></av:Paragraph><av:Paragraph Margin="0,0,0,0" FontFamily="宋体" FontSize="12" /><av:Paragraph Margin="0,0,0,0" FontFamily="宋体" FontSize="12" /></QuestionFlowDocument>";

            string temp = "<QuestionFlowDocument FontFamily=\"微软雅黑\" FontSize=\"12\" LineHeight=\"1\" PagePadding=\"5,0,5,0\" AllowDrop=\"True\"  xmlns=\"clr-namespace:QuestionBank.Controls;assembly=QuestionBank.Controls\"  xmlns:av=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><av:Paragraph Margin=\"0,0,0,0\" FontFamily=\"宋体\" FontSize=\"12\"><av:Span xml:lang=\"en-us\">Lincoln often visited hospitals ______.</av:Span></av:Paragraph><av:Paragraph Margin=\"0,0,0,0\" FontFamily=\"宋体\" FontSize=\"12\" /><av:Paragraph Margin=\"0,0,0,0\" FontFamily=\"宋体\" FontSize=\"12\" /></QuestionFlowDocument>";
            //QuestionFlowDocument qf = ExamXamlConverter.XamlToFlowDocument(temp);
            //string t = ExamXamlConverter.FlowDocumentToHtml(qf);
            string t = ExamXamlConverter.XamlToHtml(temp);
            t = t.Replace("\"", "'");
            JsonHelper helper = new JsonHelper();
            var json = helper.ModelToJson(re);
        }

        /// <summary>
        ///A test for InitWhere
        ///</summary>
        [TestMethod()]
        [DeploymentItem("Luminji.ExamWeb.Infrastructure.dll")]
        public void InitWhereTest()
        {
            SqlHelper.ConnectionString = ConfigurationManager.AppSettings["TestConn"];
            PaperRepository_Accessor target = new PaperRepository_Accessor(); // TODO: Initialize to an appropriate value
            string subjectCode = string.Empty; // TODO: Initialize to an appropriate value
            string actual = string.Empty; // TODO: Initialize to an appropriate value
            string expected = @"'21FB2FDCD4AA41C8A14776F3EA0F86C4'";
            actual = target.InitWhere("21FB2FDCD4AA41C8A14776F3EA0F86C4");
            Assert.AreEqual(expected, actual);

            expected = @"'811129BA861F4449BC442127167A5023','DE23D230E05D4AD79E55F51767D13869','30255A4BA0FF4756B7F1FBE00174BB88'";
            actual = target.InitWhere("811129BA861F4449BC442127167A5023");
            Assert.AreEqual(expected, actual);

        }
    }
}
